package com.installtime.demo.model;

import com.installtime.demo.constant.ResultCodeEnums;

/**
 * @Classname Result
 * @Description TODO
 * @Date 2020/7/1 13:48
 * @Created by W.Z
 */
public class Result<T>  {


    private int code;
    private String msg;
    private T data;

    /**
     * 查询成功
     * @param data
     * @param <T>
     * @return
     */
    public static<T> Result<T> ok(T data){

        Result<T> result = new Result<T>();
        result.code= ResultCodeEnums.QUERY_OK.getCode();
        result.msg=ResultCodeEnums.QUERY_OK.getMessage();
        result.data=data;
        return result;
    }

    /**
     * 操作成功
     * @param <T>
     * @return
     */
    public static<T> Result<T> ok(){

        Result<T> result = new Result<T>();
        result.code= ResultCodeEnums.OPERATION_OK.getCode();
        result.msg=ResultCodeEnums.OPERATION_OK.getMessage();
        return result;
    }

    /**
     * 操作失败
     * @param <T>
     * @return
     */
    public static<T> Result<T> failed(){

        Result<T> result = new Result<T>();
        result.code= ResultCodeEnums.OPERATION_FAIL.getCode();
        result.msg=ResultCodeEnums.OPERATION_FAIL.getMessage();
        return result;
    }
    public static<T> Result<T> failed(ResultCodeEnums enums){

        Result<T> result = new Result<T>();
        result.code= enums.getCode();
        result.msg=enums.getMessage();
        return result;
    }
    public static<T> Result<T> failed(int code,String msg){

        Result<T> result = new Result<T>();
        result.code= code;
        result.msg=msg;
        return result;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
